﻿using DataAccess;
using DTO;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DAO
{
    public class GiaMatHangDAO
    {
       
        public static DataTable GiaMatHang(int MaDonViTinh, int MaMatHang)
        {
            string sql = "SELECT GiaTien,SoLuongTon FROM GiaMatHang where MaMatHang ='" + MaMatHang + "'and MaDonViTinh='" + MaDonViTinh + "'";
            DataTable kq = DataConnection.ExecQuery(sql);
            return kq; ;
        }

        public static bool UpdateGia(GiaMatHangDTO gia)
        {
            string query = "UPDATE GIAMATHANG SET GiaTien='"+gia.GiaTien+"' where MaDonViTinh='"+gia.MaDonViTinh+"' and MaMatHang='"+gia.MaMatHang+"'";
            try
            {

                DataConnection.ExecNonQuery(query);
                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }
        public static bool CapNhatSoLuong(int p, int t, int slton)
        {
            string query = "UPDATE GIAMATHANG SET SoLuongTon='" + slton + "' WHERE MaDonViTinh='"+p+"' AND MaMatHang='"+t+"'";
           try{

               DataConnection.ExecNonQuery(query);
               return true;
            }
            catch(Exception)
            {
                return false;
            }
       }
    }
}
